<template>
    <div class="pageContainer">
        <el-row :gutter="20">
            <el-col :span="6" v-if="panels.length == 0" v-for="(item1, index1) in 4" :key="index1">
                <el-skeleton style="width: 100%" animated>
                    <template #template>
                        <el-card shadow="hover" class="cursor-pointer">
                            <template #header>
                                <div class="flex justify-between items-center">
                                    <el-skeleton-item variant="text" style="width: 40%" />
                                    <el-skeleton-item variant="text" style="width: 10%" />
                                </div>
                            </template>
                            <div style="text-align: left;">
                                <el-skeleton-item variant="h1" style="width: 80%" />
                            </div>
                            <template #footer>
                                <div class="flex justify-between items-center text-gray-500 text-sm">
                                    <el-skeleton-item variant="text" style="width: 40%" />
                                    <el-skeleton-item variant="text" style="width: 10%" />
                                </div>
                            </template>
                        </el-card>
                    </template>
                </el-skeleton>
            </el-col>
            <el-col :span="6" v-for="(item, index) in panels" :key="index">
                <el-card shadow="hover" class="rounded-lg">
                    <template #header>
                        <div class="flex justify-between items-center">
                            <span>{{ item.title }}</span>
                            <el-tag :type="item.unitColor==''?'success':item.unitColor">{{ item.unit }}</el-tag>
                        </div>
                    </template>
                    <div style="text-align: left;">
                        <span class="text-3xl font-bold text-gray-500">
                            <CountTo :value="item.value"></CountTo>
                        </span>
                    </div>
                    <template #footer>
                        <div class="flex justify-between items-center text-gray-500 text-sm">
                            <span>{{ item.subTitle }}</span>
                            <span>{{ item.subValue }}</span>
                        </div>
                    </template>
                </el-card>
            </el-col>
        </el-row>
        <IndexNavs/>
        <el-row :gutter="20" class="pt-5">
            <el-col :span="12">
                <IndexChart v-permission="['getStatistics3,GET']"/>
            </el-col>
            <el-col :span="12" class="flex flex-col items-center justify-center">
                <IndexCard title="店铺及商品" tip="店铺及商品提示" :data="goods" class="mb-5"></IndexCard>
                <IndexCard title="交易情况" tip="需要立即处理的交易订单" :data="order" class="mb-5"></IndexCard>
            </el-col>
        </el-row>
    </div>
</template>
<script setup>
import { getStatistics1, getStatistics2 } from '../api/index'
import { ref, onMounted } from 'vue'
import CountTo from '../components/CountTo.vue';
import IndexNavs from '../components/IndexNavs.vue';
import IndexChart from '../components/IndexChart.vue';
import IndexCard from '../components/IndexCard.vue';

const panels = ref([])
const goods = ref([])
const order = ref([])

const loadData = async () => {
    const res = (await getStatistics1()).data
    const res2 = (await getStatistics2()).data
    panels.value = res.data.panels
    goods.value = res2.data.goods
    order.value = res2.data.order
}

onMounted(() => {
    loadData();
});
</script>